<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateOrderDiscountSplite extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        return;
        for ($i = 0; $i <= 99; $i++) {

            $name = str_pad($i, 3, 0, STR_PAD_LEFT);

            Schema::connection("mysqlOrder")
                  ->create('order_discount_' . $name, function (Blueprint $table) use ($name) {
                      $table->unsignedBigInteger('id')->default(0)->comment("主键 id");
                      $table->unsignedInteger("brandId")->default(0)->comment("品牌 Id");
                      $table->unsignedInteger("shopId")->default(0)->comment("店铺 ID");
                      $table->unsignedBigInteger('orderId')->default(0)->comment("kf_orders表id");
                      $table->unsignedTinyInteger('discountType')->default(0)->comment("折扣类型，如满减券、代金券");
                      $table->unsignedInteger('discountNum')->default(0)->comment("优惠值 90 折 或者 500 分等 ");
                      $table->unsignedInteger('discountPrice')->default(0)->comment("折扣金额分 ");

                      // 统一表字段
                      $table->integer('createdAt')->default(0)->comment('创建时间');
                      $table->integer('createdByUid')->default(0)->comment('创建人');
                      $table->integer('updatedAt')->default(0)->comment('修改时间');
                      $table->integer('updatedByUid')->default(0)->comment('修改人');
                      $table->integer('isDeleted')->default(0)->comment('是否删除');

                      // 索引部分
                      $table->primary('id', 'idx_id');        // 主键非自增
                      $table->index('orderId', 'idx_orderId');  // 索引

                      $table->collation = 'utf8mb4_general_ci';
                      $table->comment   = '订单折扣表_' . $name;
                  });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//        for ($i = 0; $i <= 99; $i++) {
//            $name = str_pad($i, 3, 0, STR_PAD_LEFT);
//            Schema::connection("mysqlOrder")->dropIfExists('order_discount_' . $name);
//        }
    }
}
